<template>
  <ul class="member-list">
    <li 
      class="member-item" 
      v-for="member in members" 
      :key="member.id"
    >
      <div 
        class="member-avatar" 
        :style="{backgroundColor: getAvatarColor(member.name)}"
      >
        {{ getInitials(member.name) }}
      </div>
      <div class="member-info">
        <div class="member-name">
          {{ member.name }}{{ member.id === currentUser.id ? ' (我)' : '' }}
        </div>
        <div class="member-status">
          {{ member.audioEnabled ? '音频开启' : '音频关闭' }}，
          {{ member.videoEnabled ? '视频开启' : '视频关闭' }}
        </div>
      </div>
      <div class="member-controls">
        <button class="video-control-btn">⋮</button>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  name: 'MemberList',
  props: {
    members: {
      type: Array,
      required: true
    },
    currentUser: {
      type: Object,
      required: true
    }
  },
  methods: {
    // 获取用户姓名的首字母
    getInitials(name) {
      return name.charAt(0);
    },
    
    // 根据用户名获取头像颜色
    getAvatarColor(name) {
      const colors = ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C', '#909399', '#9c27b0', '#673ab7'];
      let hash = 0;
      for (let i = 0; i < name.length; i++) {
        hash = name.charCodeAt(i) + ((hash << 5) - hash);
      }
      return colors[Math.abs(hash) % colors.length];
    }
  }
}
</script>

<style scoped>
.member-list {
  list-style: none;
}

.member-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #333;
}

.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #409EFF;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  color: white;
}

.member-info {
  flex: 1;
}

.member-name {
  font-size: 14px;
}

.member-status {
  font-size: 12px;
  color: #999;
}

.member-controls {
  display: flex;
}

.video-control-btn {
  background-color: rgba(0, 0, 0, 0.5);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 5px;
  cursor: pointer;
}
</style>